function kf = calculate_curvature(tail, orig_vec)

act_bl = linspace(0, 1, length(tail));
% tailvec2 = interp1(act_bl, tail, orig_vec);
tailvec2 = tail;

thi = atan2((tailvec2(2:end, 2) - tailvec2(1:end-1, 2)),...
            (tailvec2(2:end, 1) - tailvec2(1:end-1, 1)))';

% Create s vector
pos=0; % Initialize to zero
% Build s vector
for ii = 2 : length(tailvec2(:, 2))
    pos(ii) = pos(ii - 1) - ...
              sqrt((tailvec2(ii, 1) - tailvec2(ii-1, 1)).^2 + ...
                   (tailvec2(ii, 2) - tailvec2(ii-1, 2)).^2);
end

pos2 = pos / max(abs(pos));
shft = find(min(abs(abs(pos2) - 0.5)) == abs(abs(pos2) - 0.5));
pos2 = pos2 - pos2(shft);
pos2 = sort(pos2);
ds =pos2(2) - pos2(1);

% Move to zero
tailvec(:, 1) = tailvec2(:, 1) - tailvec2(1, 1);
tailvec(:, 2) = tailvec2(:, 2) - tailvec2(1, 2);
for kk = 2 : length(tailvec(: ,2))
    tailvec(kk, :) = tailvec(kk - 1, :) + ...
       ds * [cos(thi(kk - 1)) sin(thi(kk - 1))];
end

% Curvature, filtering
sd = 5; rng = 3;
filt = fspecial('gaussian',[rng,1],sd);

ys = diff(tailvec(:, 2)) ./ diff(pos');
xs = diff(tailvec(:, 1)) ./ diff(pos');

ysf = imfilter(ys, filt, 'same', 'replicate');
xsf = imfilter(xs, filt, 'same', 'replicate');

yss = diff(ysf) ./ diff(pos(1:end-1)');
xss = diff(xsf) ./ diff(pos(1:end-1)');

yssf = imfilter(yss, filt, 'same', 'replicate');
xssf = imfilter(xss, filt, 'same', 'replicate');

kf = (xsf(1:end-1) .* yssf - ysf(1:end-1) .* xssf) ./ ...
     (xsf(1:end-1).^2 + ysf(1:end-1).^2).^(3/2);

orig_vec = linspace(1,length(kf),length(orig_vec)); 
kf = interp1(kf,orig_vec);
 
 
end